package dialogs;

import java.awt.event.ActionEvent;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import controllers.AbstractController;
import controllers.CustomerPurchaseController;

@SuppressWarnings("serial")
public class CreditCardDialog extends AbstractGeneralPurposeDialog {
	private CustomerPurchaseController controller;

	public CreditCardDialog(JFrame parent, AbstractController c) {
		super(parent, "Payment Method", "Credit Card Info", 
				new String[] { "Card No:", "Expiry Date"}, c);
		controller = (CustomerPurchaseController )c;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String actionCommand = e.getActionCommand();
		if (actionCommand.equals("OK")) {
			Vector<String> s = new Vector<String>();
			for (JTextField j : text_fields)
				s.add(j.getText());
			int retCode = controller.finalizeTransaction(s); 
			if ( retCode == OPERATIONSUCCESS)
					dispose();
			else if(retCode == VALIDATIONERROR)
				JOptionPane.showMessageDialog(this, "Invalid Input", "Error", JOptionPane.ERROR_MESSAGE);
			else
				JOptionPane.showMessageDialog(this, "Transaction Failed", "Error", JOptionPane.ERROR_MESSAGE);
		}
		else
			System.out.println("command: " + actionCommand);
	}

}
